<!DOCTYPE html>
<html>
<head>
    <title>透析助手</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.5.6/css/sm.min.css">
    <link rel="stylesheet" href="__PUBLIC__/css/style.css">
    <link rel="stylesheet" href="__PUBLIC__/css/5s.css">
    <link rel="stylesheet" href="__PUBLIC__/css/6m.css">
    <link rel="stylesheet" href="__PUBLIC__/css/iconfont.css">
    <style type="text/css">
        .RegisterContent input{width:55%;}
        .RegisterContent button{width:42%;}
    </style>
</head>
<body>
    <div class="head head-another">
        <div class="HeadContent">
            <a href="javascript:;" class="back"><i class="iconfont">&nbsp;</i></a>
            <div class="HeadTitleMiddle">新用户注册</div>
        </div>
	</div>
    <div class="RecordInformation-public">
        <div class="register">
            <img src="__PUBLIC__/images/register.jpg"/>
        </div>
        <div>
            <div class="RegisterTitle">
                手机号码
            </div>
            <div class="RegisterContent">
                <input type="tel" id="phone" name="phone" placeholder="请输入您的手机号码"/>
                <button type="button" class="get_num" onclick="get_mobile_code(this)" data-getStatus='0'>
                    发送验证码
                </button>
            </div>
        </div>
        <div>
            <div class="RegisterTitle">
                手机验证码
            </div>
            <div class="RegisterContent FullWidth">
                <input type="tel" name="code" placeholder="请输入验证码" />
            </div>
        </div>
    </div>

    <div class="BtnGroup">
        <button class="AddRecord btn-submit" type="button" onclick="save()">立即关联</button>
    </div>
</body>
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.5.7/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='__PUBLIC__/js/myjq.js'></script>
<script type="text/javascript">
function save(){
	if(!isMobil($('#phone').val())){
		$.toast("请填写正确的手机号");return;
	}
	if($('input[name="code"]').val()==''){
		$.toast("请填写验证码");return;
	}
    loadingShow();
	$.post(
        "<{:U('regPhone')}>",
        {phone:$('#phone').val(),code:$('input[name="code"]').val(),fromuser:'<{$fromuser}>'},
        function(res){
            loadingHide();
            if(res){
                if(res.status==1){
                    if(res.type=='1' || res.type=='3'){//医生或营养师
                        location.href="<{:U('Index/doctor')}>";
                    }else{//患者
                        location.href="<{:U('complete')}>";
                    }
                }else if(res.status==0){
                    $.toast(res.msg);
                }
            }else{
                $.toast("关联失败");
            }
        },
        'json'
    );
}

//获取手机验证码
function get_mobile_code(obj){
	if(!isMobil($('#phone').val())){
		$.toast("请填写正确的手机号");return;
	}
	//防止重复点击
	if($(obj).attr('data-getStatus')=='1') return;
	$(obj).attr('data-getStatus','1');
	
	$.post("<{:U('Public/sendPhoneMsg')}>",{mobile:$('#phone').val()},function(msg){
        if(msg == 'suc'){
            $(obj).html('<span>60</span>s后可重发');
            getCodeTimeDec();
        }else{
			$(".get_num").attr('data-getStatus','0');
            $.toast(msg);
        }
	});
};

//倒计时
var getCodeTime;
function getCodeTimeDec(){
	getCodeTime=setInterval(function(){
		var timeNum=$(".get_num span").text();
		timeNum=parseInt(timeNum)-1;
		$(".get_num span").text(timeNum);
		if(timeNum<1){
			clearInterval(getCodeTime);
			getCodeTime=null;
			$(".get_num").attr('data-getStatus','0').html('发送验证码');
		}
	},1000);
}
</script>
</html>